# Maintainer: Felix Yan <felixonmars@archlinux.org>
# Contributor: Arch Haskell Team <arch-haskell@haskell.org>

pkgname=agda-stdlib
pkgver=1.7.3
_agdaver=2.6.4
pkgrel=1
pkgdesc="Agda standard libraries"
url="https://github.com/agda/agda-stdlib"
license=("MIT")
arch=('loong64' 'x86_64')
depends=("agda=$_agdaver")
makedepends=('ghc' 'haskell-filemanip')
options=('staticlibs')
source=("$pkgname-$pkgver.tar.gz::https://github.com/agda/agda-stdlib/archive/v$pkgver.tar.gz"
        standard-library.agda-lib.in)
sha512sums=('23649e41bf52df03a448e9395360e4a1eb815940a48ae6d86e16681ecd756be6129059b8f90f78bba7aa79e7668cccca5a2f7cb39c2b920ae043b257fdbfc120'
            '9b666bd3b6122b196353b68a4a6bdf15318f276a644f04ffa001793de1c78ba7c9bd875c3011c1c0363d81c9f94f4901b9aa4766aa5f1825057a109b03021701')

prepare() {
    cd $pkgname-$pkgver
    rm standard-library.agda-lib
}

build() {
    cd $pkgname-$pkgver

    runhaskell Setup configure -O --enable-shared --enable-executable-dynamic --disable-library-vanilla
    runhaskell Setup build $MAKEFLAGS

    dist/build/GenerateEverything/GenerateEverything

    agda -i. -isrc Everything.agda --warning=noUnsupportedIndexedMatch
}

package() {
    install -Dm644 standard-library.agda-lib.in "$pkgdir"/usr/share/agda/lib/standard-library.agda-lib

    cd $pkgname-$pkgver
    install -dm755 "$pkgdir"/usr/share/agda/lib/stdlib
    cp -pr src/* "$pkgdir"/usr/share/agda/lib/stdlib/

    # Symlink to avoid writing to this place when agda-lib is present
    install -dm755 "$pkgdir"/usr/share/agda/lib/_build/$_agdaver/agda
    ln -s ../../../stdlib "$pkgdir"/usr/share/agda/lib/_build/$_agdaver/agda/

    install -D -m644 LICENCE "$pkgdir"/usr/share/licenses/$pkgname/LICENCE
}
